<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Exit</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>Exit</h1>

<p>Exits the <a href="../misc/Threads.htm">current thread</a> or (if the script is not <a href="_Persistent.htm">persistent</a> and contains no hotkeys) the entire script.</p>

<pre class="Syntax">Exit [, ExitCode]</pre>
<h3>Parameters</h3>
<dl>

  <dt>ExitCode</dt>
  <dd><p>An integer between -2147483648 and 2147483647 (can be an <a href="../Variables.htm#Expressions">expression</a>) that is returned to its caller when the script exits. This code is accessible to any program that spawned the script, such as another script (via RunWait) or a batch (.bat) file. If omitted, <em>ExitCode</em> defaults to zero. Zero is traditionally used to indicate success.</dd>

</dl>

<h3>Remarks</h3>
<p>If the script has no hotkeys, isn't <a href="_Persistent.htm">persistent</a>, and hasn't requested the Num/Scroll/CapsLock key(s) to be kept AlwaysOn or AlwaysOff, it will terminate immediately when Exit is encountered (except if it has an <a href="OnExit.htm">OnExit</a> subroutine).</p>
<p>Otherwise, the Exit command terminates the <a href="../misc/Threads.htm">current thread</a>. In other words, the stack of subroutines called directly or indirectly by a <a href="Menu.htm">menu</a>, <a href="SetTimer.htm">timer</a>, or <a href="../Hotkeys.htm">hotkey</a> subroutine will all be returned from as though a <a href="Return.htm">Return</a> were immediately encountered in each. If used directly inside such a subroutine -- rather than in one of the subroutines called indirectly by it -- Exit is equivalent to <a href="Return.htm">Return</a>.</p>
<p>Use <a href="ExitApp.htm">ExitApp</a> to completely terminate a script that is <a href="_Persistent.htm">persistent</a> or contains hotkeys.</p>
<h3>Related</h3>
<p><a href="ExitApp.htm">ExitApp</a>, <a href="OnExit.htm">OnExit</a>, <a href="../Functions.htm">Functions</a>, <a href="Gosub.htm">Gosub</a>, <a href="Return.htm">Return</a>, <a href="../misc/Threads.htm">Threads</a>, <a href="_Persistent.htm">#Persistent</a></p>
<h3>Example</h3>
<pre class="NoIndent">#z::
Gosub, Sub2
MsgBox, This msgbox will never happen because of the EXIT.
return

Sub2:
Exit  <em>; Terminate this subroutine as well as the calling subroutine.</em></pre>

</body>
</html>
